<?php
require_once(SITE_ROOT.'/includes/application/SignApplication.php');
require_once(SITE_ROOT.'/includes/application/Application.php');
require_once("SpacePageComponent.php");

class UserInfoSpaceComponent extends SpacePageComponent {
	protected $app,$userId;
	public function __construct($app,$userId){
		$this->app = $app;
		$this->userId = $userId;
	}
	public function getTemplate(){
		return "member/userinfoSpace.dwt";
	}
	public function closeable(){
		return true;
	}
	public function minimizable(){
		return false;
	}
	private function processDisplay(&$recordset){
		if(!is_array($recordset) )
            return;
        $temparr = explode(".",$recordset['src']);
        $recordset['mainphoto'] = $recordset['src'] == "default.gif" ? "" : $recordset['src'];
        $recordset['src'] = "/static/user/".$this->userId."/face/".$temparr[0]."_xl.".$temparr[1];
        $userInfoPercent = array("realname","birth-year","birth-month","birth-day","mainphoto");
			$percent = 0;
			$bind_info_exit = 0;
			foreach ($userInfoPercent as $content){
				if(trim($recordset[$content]) != "" && $recordset[$content]!='-1' && $recordset[$content]!='0000-00-00' ){
					    $percent++;
				}
			}
		$recordset["userProfilePercent"] =ceil(($percent / ( count($userInfoPercent) ) * 100));	
	}
	public function prepare($ajax=false){
		global $gSmarty;
        $recordlist = $this->app->getUserSimpleDetail($this->userId);
        $this->processDisplay($recordlist);
        $gSmarty->assign( "UserInfo",$recordlist);
        if( $ajax==false ){
			$gSmarty->assign( "userInfo_dwt",$this->getTemplate());
		}else{		    
			return $gSmarty->fetch($this->getTemplate());
		}
	
        
	}
}

?>